package com.projects.xenia.ref_classes;

import android.database.Cursor;	
import com.projects.xenia.global_modules.MainGlobalModule;

public class VisitCausesRefObject {
	
	public VisitCausesRefItem RefItem;
	
	public VisitCausesRefObject () {
		
		RefItem = new VisitCausesRefItem();
		
	}
	
	
	public VisitCausesRefObject (String cause_id) {
	
		RefItem = new VisitCausesRefItem();
		SetVisitCauseById (cause_id);
		
	}

	public void SetVisitCauseById (String cause_id) {
		
		if (cause_id != null) {
			
			Cursor VisitCausesCursor = MainGlobalModule.DBE.rawQuery("select id, descr from xref_VisitCauses where id = ?", new String [] {cause_id});
			
			if (VisitCausesCursor.getCount()>0) {
			
				RefItem = new VisitCausesRefItem();
				
				VisitCausesCursor.moveToFirst();
				
				RefItem.id =  VisitCausesCursor.getString(0);
				RefItem.descr =  VisitCausesCursor.getString(1);

			}
			
			else {
				
				RefItem.id = cause_id;
				RefItem.descr = "<object not found>";
			}
				
			VisitCausesCursor.close();
	
		}
			
	}
	
}
